package Articulo.src.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import Articulo.src.business.managers.ArticleMgr;
import business.entities.*;

import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;

import net.miginfocom.swing.MigLayout;
import business.entities.*;





public class agregar extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField txtNombre;
	private JTextField txtPrecio;
	private JTextField txtIngredientes;
	private JTextField txtDescripcion;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					agregar frame = new agregar();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public agregar() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new MigLayout("", "[][][][grow]", "[][][][][][][][]"));
		
		JLabel lblNombre = new JLabel("Nombre");
		contentPane.add(lblNombre, "cell 1 1");
		
		txtNombre = new JTextField();
		
		contentPane.add(txtNombre, "cell 3 1,growx");
		txtNombre.setColumns(10);
		
		JLabel lblPrecio = new JLabel("Precio");
		contentPane.add(lblPrecio, "cell 1 2");
		
		txtPrecio = new JTextField();
		
		contentPane.add(txtPrecio, "cell 3 2,growx");
		txtPrecio.setColumns(10);
		
		JLabel lblCategoria = new JLabel("Categoria");
		contentPane.add(lblCategoria, "cell 1 3");
		
		final JComboBox comboBox = new JComboBox();
		contentPane.add(comboBox, "cell 3 3,growx");
		
		JLabel lblIngredientes = new JLabel("ingredientes");
		contentPane.add(lblIngredientes, "cell 1 4");
		
		txtIngredientes = new JTextField();
		
		contentPane.add(txtIngredientes, "cell 3 4,growx");
		txtIngredientes.setColumns(10);
		
		JLabel lblDescripcion = new JLabel("descripcion");
		contentPane.add(lblDescripcion, "cell 1 5");
		
		txtDescripcion = new JTextField();
		
		contentPane.add(txtDescripcion, "cell 3 5,growx");
		txtDescripcion.setColumns(10);
		
		JButton btnAgregar = new JButton("AGREGAR");
		btnAgregar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String n= txtNombre.getText();
				int p = Integer.parseInt(txtPrecio.getText());
				Category c = new Category((String)comboBox.getSelectedItem());
				String ing = txtIngredientes.getText();
				String[] ings = ing.split(" " );
				
				ArticleMgr ar = new ArticleMgr();
				String descrip = txtDescripcion.getText();
				confirmAdd conf = new confirmAdd(n,p, (String)comboBox.getSelectedItem(), ing, descrip);
				conf.setVisible(true);
			}
		});
		contentPane.add(btnAgregar, "cell 3 7");
	}

}
